<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="#">代理商管理</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<form action="${ctx}/platManager/agentManageList" id="listForm">
				<div class="box-header">
					<div class="row RowSearchWork">
						<div class="col-sm-12">
							<div class="col-sm-2 special-style" style="width: 400px; padding-left: 90px;">
								<label>关键字：</label>
								<select class="form-control" name="keywordType" style="display: inline-block;width: auto;">
									<option value="0" <#if keywordType?? && keywordType == 0>selected="selected"</#if> >--全部--</option>
									<option value="1" <#if keywordType?? && keywordType == 1>selected="selected"</#if> >名称</option>
									<option value="2" <#if keywordType?? && keywordType == 2>selected="selected"</#if> >登录名</option>
								</select>
								<input name="keyword" type="text" class="form-control" value="${keyword!}" placeholder="请输入关键字" style="display: inline-block;width: 180px;margin-left: 5px;" />
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-default btn-search" onclick="plat.query();" value="查询" />
							</div>
							<div class="col-sm-1">
								<input type="button" class="btn btn-primary" onclick="plat.form();" value="新增" />
							</div>
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th style="width:60px;">序号</th>
								<th>登录名</th>
								<th style="width:20%;">名称</th>
								<th>联系电话</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as p>
							<tr>
								<td>${page.size * page.number + p_index + 1}</td>
								<th>${p.loginName!}</th>
								<th>${p.nickName!}</th>
								<td>${p.phone!}</td>
								<td>
									<#if p.state?? && p.state==100>
										启用
										<#else>
										禁用
									</#if>
								<td>
									<#if p.state == 100>
										<a href="javascript:;" onclick="plat.abledForm('${p.id!}', 200)">禁用</a>
									<#else>
										<a href="javascript:;" onclick="plat.abledForm('${p.id!}', 100)">启用</a>
									</#if>
									<a href="javascript:;" onclick="plat.form('${p.id!}')">编辑</a>
									<a href="javascript:;" onclick="plat.resetPwd('${p.id!}')">重置密码</a>
									<a href="javascript:;" onclick="plat.authorityManage('${p.id!}')">功能授权</a>
								</td>
							</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</form>
		</div>
	</section>
</div>
<script type="text/javascript">
	var is_submit=false;
	var plat = {
		query : function() {
			$(":input[name='pageNumber']").val(0);
			$("form").submit();
		},
		/* 禁用启用 */
		abledForm : function (id, state) {
			$.ajax({
				url : "${ctx}/platManager/changeState",
				type : 'post',
				dataType : 'json',
				async : false,
				data : {"id" : id, "state" : state},
				success : function(data) {
					if (data.result == 'success') {
						$("#listForm").submit();
					}
				}
			});
		},
		/* 新增编辑 */
		form : function(id){
			if(is_submit){
				return;
			}
			is_submit=true;
			id = id ? id : "";
			var title = id ? "修改代理商" : "新增代理商";
			var j = 0;
			base.getView({
				url:"${ctx}/platManager/hqAgentForm?id="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function(){
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#addForm"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			})
		},
		/* 重置密码 */
		resetPwd : function (id) {
			if(is_submit){
				return;
			}
			is_submit = true;
			var title = '重置密码';
			var j = 0;
			base.getView({
				url:"${ctx}/platManager/resetPassWord?id="+id,
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"small",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function() {
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#resetForm"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			});
		},
		/* 功能授权 */
		authorityManage : function (id) {
			if(is_submit){
				return;
			}
			is_submit = true;
			var title = '功能授权';
			var j = 0;
			base.getView({
				url:"${ctx}/platManager/menuAuthority?id="+id+"&userType=3",
				success:function(result){
					bootbox.dialog({
						title:title,
						message:result,
						size:"large",
						closeButton : false,
						buttons:{
							cancel:{
								label:"取消",
								className:"btn btn-secondary",
								callback:function(){
									is_submit=false;
								}
							},
							sure:{
								label:"确定",
								className:"btn btn-primary",
								callback:function() {
									if (j != 0) {
										is_submit=false;
										return ;
									}
									j++;
									base.validAndAjaxSubmit($("#authorityForm"), $("#listForm"), function () {
										j = 0;
									});
									return false;
								}
							}
						}
					})
				}
			});
		}
	}
</script>
<#include "../common/footer.htm">